#include "BdPluginRegistry.h"
#include "BdPlugin.h"
#include "BdPluginMetadata.h"

#include <QString>

BdPluginRegistry::BdPluginRegistry()
{
  //Noop
}

BdPluginRegistry *BdPluginRegistry::mInstance = 0;
BdPluginRegistry *BdPluginRegistry::instance()
{
  if (mInstance == 0)
  {
    mInstance = new BdPluginRegistry();
  }
  return mInstance;
}

void BdPluginRegistry::addPlugin(QString nom, QString libraryPath, BdPlugin* plugin)
{
  plugins[nom] = new BdPluginMetadata(nom, libraryPath, plugin);
}

void BdPluginRegistry::removePlugin(QString nom)
{
  plugins.remove(nom);
}

BdPlugin *BdPluginRegistry::plugin(QString nom)
{
  BdPluginMetadata *pmd = plugins[nom];
  BdPlugin *retval = 0;
  if (pmd)
  {
    retval = pmd->plugin();
  }
  return retval;
}

QString BdPluginRegistry::path(QString pluginKey)
{
  BdPluginMetadata *pmd = plugins[pluginKey];
  QString retval;
  if (pmd)
  {
    retval = pmd->path();
  }
  return retval;
}

